/*
 * estadoInicial.java
 *
 * Created on 5 de septiembre de 2008, 09:26 AM
 */

package administrador;
public class estadoInicial extends javax.swing.JPanel {
    Conexion conexion;
    String fecha="";
    int filasA=0;
    int filasP=0;
    int filasPT=0;
    public estadoInicial(Conexion conexion) {
        this.conexion=conexion;
        initComponents();
       
        String consulta="";
        consulta="select * from tercernivel  where cod_primernivel=1 order by cod_primernivel";
        java.sql.ResultSet consultaActivo=conexion.consultarBase(consulta);
        muestroTablaA(consultaActivo,consulta,tabla_activo);
        filasA=conexion.obtenerFilas(consultaActivo);    
        
        consulta="select * from tercernivel  where cod_primernivel=2 order by cod_primernivel";
        consultaActivo=conexion.consultarBase(consulta);
        muestroTablaA(consultaActivo,consulta,tabla_pasivo);
        filasP=conexion.obtenerFilas(consultaActivo);    
        
        consulta="select * from tercernivel  where cod_primernivel=3 order by cod_primernivel";
        consultaActivo=conexion.consultarBase(consulta);
        muestroTablaA(consultaActivo,consulta,tabla_pa);
        filasPT=conexion.obtenerFilas(consultaActivo);    
        fecha=new java.sql.Date(System.currentTimeMillis()).toString();
    }
    public void asientoActivos(){
      try{
        conexion.consultarBase("START TRANSACTION;");
        String numeroDiario=numeroDiario();
        asiento(numeroDiario,fecha,"Asiento Incial de Activos");
        String numeroAsiento=numeroAsiento();
        for(int i=0;i<filasA;i++){
          try{
                  String valor=tabla_activo.getValueAt(i,4).toString();
                  if(valor.equals("")){
                      valor="0";    
                  }
                  asientoDeatlle(numeroAsiento,numeroDiario,tabla_activo.getValueAt(i,0).toString(),tabla_activo.getValueAt(i,1).toString(),tabla_activo.getValueAt(i,2).toString(),"0",valor,"0");
          }catch(java.lang.NullPointerException f){}
          
        }
        //asiento(numeroDiario,fecha,"Asiento Incial de Pasivos");
        //String numeroAsiento1=numeroAsiento();
        for(int i=0;i<filasP;i++){
            try{
                  String valor=tabla_pasivo.getValueAt(i,4).toString();
                  if(valor.equals("")){
                      valor="0";    
                  }
                  asientoDeatlle(numeroAsiento,numeroDiario,tabla_pasivo.getValueAt(i,0).toString(),tabla_pasivo.getValueAt(i,1).toString(),tabla_pasivo.getValueAt(i,2).toString(),"0","0",valor);
            }catch(java.lang.NullPointerException f){}
        }
        
        //asiento(numeroDiario,fecha,"Asiento Incial de Patrimonio");
        // numeroAsiento2=numeroAsiento();
        for(int i=0;i<filasPT;i++){
            try{
                      String valor=tabla_pa.getValueAt(i,4).toString();
                      if(valor.equals("")){
                          valor="0";    
                      }
                      asientoDeatlle(numeroAsiento,numeroDiario,tabla_pa.getValueAt(i,0).toString(),tabla_pa.getValueAt(i,1).toString(),tabla_pa.getValueAt(i,2).toString(),"0","0",valor);
              }catch(java.lang.NullPointerException f){}
        }
        conexion.insertarDatos("insert into estadoinicial(diario) values("+numeroDiario+")");
        conexion.consultarBase("COMMIT;");
        conexion.limpiar(tabla_pa);
        conexion.limpiar(tabla_pasivo);
        conexion.limpiar(tabla_activo);
        txt_totalActivo.setText("0.0");
        txt_totalPasivo.setText("0.0");
        txt_TotalPatrimonio.setText("0.0");
        txt_cuadre.setText("0.0");
     }catch(Exception sqle){
        conexion.consultarBase("ROLLBACK;");
     }
     
    }
    public boolean verificaExistencia(){
        boolean existe=false;
        String numeroDiario=numeroDiario();
            try{   
                if(numeroDiario.equals(null)){}else{
                        existe=false;
                    if(incialDiario().equals(null)){
                        existe=false;
                    }else{
                        if(numeroDiario.equals(incialDiario())){
                            existe=true;
                        }
                    }
                }
            }catch(java.lang.NullPointerException h){} 
        return existe;
    }
    public String incialDiario(){
        String numero="";
        try{
            java.sql.ResultSet r=conexion.consultarBase("select MAX(diario) from estadoinicial");
            r.next();
            numero=r.getString(1);
        }
        catch(java.lang.NullPointerException h){} 
        catch(java.sql.SQLException f){
        }
        return numero;
    }
    public String numeroDiario(){
         String numero=""; 
         try{
            java.sql.ResultSet r=conexion.consultarBase("select  cod_diario from diario where fecha_diario=(select max(fecha_diario) from diario) limit 1");
            r.next();
            numero=r.getString(1);
          }catch(java.sql.SQLException f){}
         return numero;
    }
    public String numeroAsiento(){
         String numero=""; 
         try{
            java.sql.ResultSet r=conexion.consultarBase("select max(cod_asiento) from asiento");
            r.next();
            numero=r.getString(1);
          }catch(java.sql.SQLException f){}
         return numero;
    }
    public void asiento(String numeroDiario,String fecha,String referencia){
        conexion.insertarDatos("insert into asiento(cod_diario,fecha_dia,referencia) values("+numeroDiario+",'"+fecha+"','"+referencia+"')");
    }
    public void asientoDeatlle(String numeroAsiento,String numeroDiario,String n3,String n2,String n1,String parcial,String debe,String haber){
        String consultaDtlAs= "insert into dtl_asiento "+
                              "(cod_diario,cod_asiento,cod_tercernivel,cod_segundonivel,cod_primernivel,parcial,debe,haber) " +
                              "values ("+numeroDiario+","+numeroAsiento+","+n3+","+n2+","+n1+","+parcial+","+debe+","+haber+")";
        conexion.insertarDatos(consultaDtlAs);
    }
    
    public void muestroTablaA(java.sql.ResultSet respuesta,String consulta,javax.swing.JTable tabla){
        java.util.Vector vecPrincipal=conexion.consulta(consulta);
        java.util.Vector vecInterno=new java.util.Vector();
        for(int i=0;i<vecPrincipal.size();i++){
           vecInterno=(java.util.Vector)vecPrincipal.elementAt(i);
           tabla.setValueAt(vecInterno.elementAt(0),i,0);  
           tabla.setValueAt(vecInterno.elementAt(1),i,1); 
           tabla.setValueAt(vecInterno.elementAt(2),i,2); 
           tabla.setValueAt(vecInterno.elementAt(3),i,3); 
           tabla.setValueAt(new Double(0),i,4); 
        }
    } 
    public double sumaValores(javax.swing.JTable tabla){
        double suma=0.0;
        for(int i=0;i<filasA;i++){
          try{
                  String valor=tabla.getValueAt(i,4).toString();
                  if(valor.equals("")){
                      valor="0.0";    
                  }
                  suma+=Double.parseDouble(valor);
          }catch(java.lang.NullPointerException f){}
        }
        return suma;
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txt_totalActivo = new javax.swing.JTextField();
        txt_totalPasivo = new javax.swing.JTextField();
        txt_TotalPatrimonio = new javax.swing.JTextField();
        btn_guaradInicial = new javax.swing.JButton();
        pn_activos = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla_activo = new javax.swing.JTable();
        pn_pasivo = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabla_pasivo = new javax.swing.JTable();
        pn_patrimonio = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabla_pa = new javax.swing.JTable();
        txt_cuadre = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        txt_totalActivo.setEditable(false);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(estadoInicial.class);
        txt_totalActivo.setText(resourceMap.getString("txt_totalActivo.text")); // NOI18N
        txt_totalActivo.setName("txt_totalActivo"); // NOI18N

        txt_totalPasivo.setEditable(false);
        txt_totalPasivo.setText(resourceMap.getString("txt_totalPasivo.text")); // NOI18N
        txt_totalPasivo.setName("txt_totalPasivo"); // NOI18N

        txt_TotalPatrimonio.setEditable(false);
        txt_TotalPatrimonio.setText(resourceMap.getString("txt_TotalPatrimonio.text")); // NOI18N
        txt_TotalPatrimonio.setName("txt_TotalPatrimonio"); // NOI18N

        btn_guaradInicial.setText(resourceMap.getString("btn_guaradInicial.text")); // NOI18N
        btn_guaradInicial.setName("btn_guaradInicial"); // NOI18N
        btn_guaradInicial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_guaradInicialActionPerformed(evt);
            }
        });

        pn_activos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("pn_activos.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("pn_activos.border.titleFont"))); // NOI18N
        pn_activos.setName("pn_activos"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tabla_activo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nivel 1", "Nivel 2", "Nivel 3", "Cuenta", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabla_activo.setName("tabla_activo"); // NOI18N
        tabla_activo.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                tabla_activoInputMethodTextChanged(evt);
            }
        });
        tabla_activo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tabla_activoPropertyChange(evt);
            }
        });
        tabla_activo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tabla_activoKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(tabla_activo);

        javax.swing.GroupLayout pn_activosLayout = new javax.swing.GroupLayout(pn_activos);
        pn_activos.setLayout(pn_activosLayout);
        pn_activosLayout.setHorizontalGroup(
            pn_activosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_activosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                .addContainerGap())
        );
        pn_activosLayout.setVerticalGroup(
            pn_activosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_activosLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                .addContainerGap())
        );

        pn_pasivo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("pn_pasivo.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("pn_pasivo.border.titleFont"))); // NOI18N
        pn_pasivo.setName("pn_pasivo"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tabla_pasivo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nivel 1", "Nivel 2", "Nivel 3", "Cuenta", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabla_pasivo.setName("tabla_pasivo"); // NOI18N
        tabla_pasivo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tabla_pasivoPropertyChange(evt);
            }
        });
        jScrollPane2.setViewportView(tabla_pasivo);

        javax.swing.GroupLayout pn_pasivoLayout = new javax.swing.GroupLayout(pn_pasivo);
        pn_pasivo.setLayout(pn_pasivoLayout);
        pn_pasivoLayout.setHorizontalGroup(
            pn_pasivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_pasivoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                .addContainerGap())
        );
        pn_pasivoLayout.setVerticalGroup(
            pn_pasivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_pasivoLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pn_patrimonio.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("pn_patrimonio.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("pn_patrimonio.border.titleFont"))); // NOI18N
        pn_patrimonio.setName("pn_patrimonio"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        tabla_pa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nivel 1", "Nivel 2", "Nivel 3", "Cuenta", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabla_pa.setName("tabla_pa"); // NOI18N
        tabla_pa.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tabla_paPropertyChange(evt);
            }
        });
        jScrollPane3.setViewportView(tabla_pa);

        javax.swing.GroupLayout pn_patrimonioLayout = new javax.swing.GroupLayout(pn_patrimonio);
        pn_patrimonio.setLayout(pn_patrimonioLayout);
        pn_patrimonioLayout.setHorizontalGroup(
            pn_patrimonioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pn_patrimonioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                .addContainerGap())
        );
        pn_patrimonioLayout.setVerticalGroup(
            pn_patrimonioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
        );

        txt_cuadre.setEditable(false);
        txt_cuadre.setText(resourceMap.getString("txt_cuadre.text")); // NOI18N
        txt_cuadre.setName("txt_cuadre"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setForeground(resourceMap.getColor("jLabel5.foreground")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btn_guaradInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(7, 7, 7)
                                        .addComponent(txt_totalActivo, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(99, 99, 99)
                                        .addComponent(jLabel4))
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txt_cuadre, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txt_TotalPatrimonio, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(pn_activos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(133, 133, 133)
                                                .addComponent(jLabel1)
                                                .addGap(18, 18, 18)
                                                .addComponent(txt_totalPasivo))
                                            .addGroup(layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(pn_pasivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(pn_patrimonio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
                    .addComponent(jLabel5))
                .addContainerGap(155, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pn_pasivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txt_totalPasivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pn_patrimonio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(pn_activos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_TotalPatrimonio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_cuadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_guaradInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(txt_totalActivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel2)))
                .addGap(19, 19, 19))
        );
    }// </editor-fold>//GEN-END:initComponents

private void btn_guaradInicialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_guaradInicialActionPerformed
   double cuadre=Double.valueOf(txt_totalActivo.getText())-Double.valueOf(txt_cuadre.getText());
    
    if(cuadre==0){
       asientoActivos();
    }else{ 
       javax.swing.JOptionPane.showMessageDialog(this,"Total Activo Debera ser Igual a Total Activo + Patrimonio","Informacion",javax.swing.JOptionPane.INFORMATION_MESSAGE);
    }   
}//GEN-LAST:event_btn_guaradInicialActionPerformed
int numero;
private void tabla_activoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tabla_activoPropertyChange
  txt_totalActivo.setText(String.valueOf(sumaValores(tabla_activo)));
  double totPasPatr=Double.parseDouble(txt_totalPasivo.getText())+Double.parseDouble(txt_TotalPatrimonio.getText());
  double sumaTotal=totPasPatr;
  txt_cuadre.setText(String.valueOf(totPasPatr));
}//GEN-LAST:event_tabla_activoPropertyChange

private void tabla_activoInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tabla_activoInputMethodTextChanged
      
}//GEN-LAST:event_tabla_activoInputMethodTextChanged

private void tabla_pasivoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tabla_pasivoPropertyChange
    txt_totalPasivo.setText(String.valueOf(sumaValores(tabla_pasivo)));
    double totPasPatr=Double.parseDouble(txt_totalPasivo.getText())+Double.parseDouble(txt_TotalPatrimonio.getText());
    double sumaTotal=totPasPatr;
    txt_cuadre.setText(String.valueOf(totPasPatr));
}//GEN-LAST:event_tabla_pasivoPropertyChange

private void tabla_paPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tabla_paPropertyChange
    txt_TotalPatrimonio.setText(String.valueOf(sumaValores(tabla_pa)));
    double totPasPatr=Double.parseDouble(txt_totalPasivo.getText())+Double.parseDouble(txt_TotalPatrimonio.getText());
    double sumaTotal=totPasPatr;
    txt_cuadre.setText(String.valueOf(totPasPatr));
}//GEN-LAST:event_tabla_paPropertyChange

private void tabla_activoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabla_activoKeyTyped
}//GEN-LAST:event_tabla_activoKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_guaradInicial;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel pn_activos;
    private javax.swing.JPanel pn_pasivo;
    private javax.swing.JPanel pn_patrimonio;
    private javax.swing.JTable tabla_activo;
    private javax.swing.JTable tabla_pa;
    private javax.swing.JTable tabla_pasivo;
    private javax.swing.JTextField txt_TotalPatrimonio;
    private javax.swing.JTextField txt_cuadre;
    public javax.swing.JTextField txt_totalActivo;
    private javax.swing.JTextField txt_totalPasivo;
    // End of variables declaration//GEN-END:variables

}
